const router = require("koa-router")();
const upload = require("../util/upload");

router.get("/", async (ctx, next) => {
  await ctx.render("index", {
    title: "Hello Koa 2!"
  });
});

router.get("/string", async (ctx, next) => {
  ctx.body = "koa2 string";
});

router.get("/json", async (ctx, next) => {
  ctx.body = {
    title: "koa2 json"
  };
});

router.post("/upload", upload.config.single("file"), async (ctx, next) => {
  // console.log(ctx, "____ctx.req.file___", upload.config);
  upload.uploadFile(ctx);
});

module.exports = router;
